package com.abel.day0227;

import java.util.ArrayList;

/**
 * @author xiachao
 * @date 2019/2/27
 */
public class Solution {

    public int minNumberInRotateArray(int [] array) {
        int len = array.length;
        if(len==0){
            return 0;
        }
        for(int i=0;i<len-1;i++){
            if(array[i+1] < array[i]){
                return array[i+1];
            }
        }
        return array[0];
    }
    public int JumpFloor(int target) {
        int [] dp = new int[target + 1];
        if(target <= 1){
            return 1;
        }
        dp[0] = 1;
        dp[1] = 1;
        for(int i=2;i<=target;i++){
            for(int j=1;j<=i;j++){
                dp[i] += dp[i - j];
            }
        }
        return dp[target];
    }

    public int RectCover(int target) {
        if(target <= 2){
            return target;
        }
        int [] dp = new int[target+1];
        dp[1] = 1;
        dp[2] = 2;
        for(int i=3;i<=target;i++){
            dp[i] = dp[i-1] + dp[i-2];
        }
        return dp[target];
    }

    public double Power(double base, int exponent) {
        if(exponent==0){
            return 1;
        }
        double cur = 1;
        int exp = exponent;
        if(exp<0){
            exp = -exp;
        }
        for(int i=1;i<=exp;i++){
            cur *= base;
        }
        return exponent>0?cur:1.0/cur;
    }

    public void reOrderArray(int [] array) {
        int [] tp = array.clone();
        int len = array.length;
        int h = 0;
        int t = len - 1;
        for(int i=0;i<len;i++){
            if(tp[i]%2==1){
                array[h++] = tp[i];
            }
            if(tp[len-1-i]%2==0){
                array[t--] = tp[len-1-i];
            }
        }
    }

    public static void main(String[] args) {
        //int [] array = {1,2,3, 4,5};
        //System.out.println(new Solution().Power(2, -3));
//        int [] array = {5,3,8,9,2,6,7,4,1};
//        new Solution().reOrderArray(array);
//        for(int i : array){
//            System.out.print(i+", ");
//        }
        ArrayList list = new ArrayList();
        System.out.println(list.toString());
    }
}
